Assessment declaration checklist

Please carefully read the statements below and check each box if you agree with the declaration. If you do not check all boxes, your assignment will not be marked. If you make a false declaration on any of these points, you may be investigated for academic misconduct. Students found to have breached academic integrity may receive official warnings and/or serious academic penalties. Please read more about academic integrity here. If you are unsure about any of these points or feel your assessment might breach academic integrity, please contact your course coordinator for support. It is important that you DO NOT submit any assessment until you can complete the declaration truthfully.

By checking the boxes below, I declare the following:

I understand that:

I agree and acknowledge that:

Antibiotic Resistance: A Comprehensive Analysis

Statement of Purpose

The aim of this study is two-fold: 1. To provide an effective visualization that educates the general public about the dangers of excessive antibiotic use. 2. To offer infectious disease doctors a quick yet comprehensive overview of antibiotic resistance in commonly encountered bacteria.

Introduction

The following report aims to provide a detailed understanding of a dataset concerning antibiotic resistance across various bacterial species. This topic is of growing concern in the medical and scientific community.


Columns Explained

Column Description
Bacterium Name Scientific name of the bacteria.
Causes Diseases or conditions that the bacteria typically cause.
Gram-negative? Indicates whether the bacterium is Gram-negative (‘yes’ or ‘no’).
Individual Drugs Resistance levels to specific antibiotics, represented as percentages.
Remarks Additional comments about antibiotic resistance.
Resistance Score A scale from 1-4 indicating the level of concern, with higher scores being more concerning.
N Antibiotics or Classes Number of antibiotics or classes showing at least some resistance.
Average % Resistance Calculated average resistance score across all considered antibiotics.

Key Highlights

Bacterial Species of Concern

  1. A. baumanii
    • Nicknamed “Iraqibacter”
    • High resistance to multiple antibiotics
    • Resistance score: 4
  2. E. faecium
    • 75% resistance to a specific antibiotic
    • Average resistance: 47%
  3. N. gonorrhoeae
    • Causes gonorrhea
    • Resistance score: 3
    • 14.35% average resistance
  4. M. tuberculosis
    • Extremely drug-resistant variants
    • Resistance score: 3
  5. S. aureus
    • 25.90% average resistance but to only one antibiotic class
  6. Note After 1992
    • No major new antibiotics have been developed for over 20 years.
  7. Gram-negative Bacteria
    • Typically more resistant due to their cell wall structure.

Key Concerns

  1. Rising Resistance: Resistance is stable or increasing for many bacteria.
  2. Multi-drug Resistance: Resistance to multiple classes of antibiotics.
  3. Gram-negative Bacteria: More resistant and increasing so over time.
  4. Data Gaps: Unquantified resistances could underrepresent actual resistance levels.

Conclusion

This dataset serves as a snapshot that underlines the urgency for new antibiotics and effective strategies to manage antibiotic resistance. It calls for immediate action from both the medical community and policymakers.


References

Deconstruct

Original

The original data visualisation selected for the assignment was as follows:


Source: informationisbeautiful.net (July 2014).


Objective and Audience

The objective and audience of the original data visualisation chosen can be summarised as follows:

Objective

Audience

Critique

The visualisation chosen had the following three main issues:

  • hard for common audience with no medical background to identify issues
  • blindness issues
  • Preattentive Processing - Shapes and sizes of the circle is not unified (area is not obvious and overlapping on the grid), light/dark, use density mislead, Area (highlight timeline: no development new antibiotics for 20 years and the resistance of existing antibiotics) not compare on the same scale No major visually saying that no major new antibiotics develop in 20 years

Changes in new visualization: + Gestalt Laws: proximity (cluster together so a group?), similarity -> corrrect using symmetry to compare side by side, auto interpreted as the foreground (Figure Ground Principle) + Use Length to represent position - common scale - same scale but unaligned for 2 cat + Color - Hue (different color viz for nominal variables) + Use dodge method to have position adjustment. Other methods (filling, jiterring, nudging, stacking) + Faceting + Coordinate systems: Cartesian

data and aesthetic mappings,
• geometric objects,
• scales, and
• facet specification.
We have also touched on two other components:
• statistical transformations, and
• the coordinate system.

Reconstruct

Code

The following code was used to fix the issues identified in the original.

# Read and preprocess libraries
library(readxl)
library(dplyr)
library(stringr)
library(writexl)

# Load necessary libraries
library(ggplot2)
library(tidyr)

Pre-processing

Data: In July 2014, the dataset on antibiotic resistance was sourced from informationisbeautiful.net. I have independently verified the integrity and accuracy of this data in 2023 against original sources, including the Centre for Disease Dynamics, World Health Organisation, and CDC (US data). Subsequent data processing and formatting to generate a tailored dataframe were conducted using the R programming language.

# Comment: Read Excel data from the first sheet
data <- read_excel("../data/antibiotic_data.xlsx", sheet = 1)

# Comment: Rename Columns
# Assuming the first row has column names that need renaming
names(data) <- str_replace_all(names(data), c(" " = "_", "%" = "percent", "-" = "_"))

# Comment: Save the cleaned data into a new CSV file
write.csv(data, "../data/cleaned_antibiotic_data.csv", row.names = FALSE)

data
## # A tibble: 20 × 49
##    Antibiotic_…¹ by_In…² Antib…³ Penic…⁴ Penic…⁵ Amino…⁶ Amino…⁷ Other…⁸ Macro…⁹
##    <chr>         <chr>   <chr>   <chr>   <chr>   <chr>   <chr>   <chr>   <chr>  
##  1 Adding up dr… "data … Indivi… all     Penici… all     Strept… Chlora… all    
##  2 Bacterium na… "Cause… Gram n… <NA>    <NA>    <NA>    <NA>    <NA>    <NA>   
##  3 A. baumanii   "\"Ira… yes     x       x       0.46    <NA>    <NA>    x      
##  4 K. pneumoniae "pneum… yes     <NA>    <NA>    0.08    <NA>    <NA>    <NA>   
##  5 E. faecium    "urina… <NA>    <NA>    <NA>    <NA>    <NA>    <NA>    <NA>   
##  6 N. gonorrhoe… "gonor… yes     0.3     x       <NA>    <NA>    <NA>    <NA>   
##  7 Shigella      "dysen… yes     <NA>    <NA>    <NA>    0.56    0.14    <NA>   
##  8 M. tuberculo… "tuber… <NA>    <NA>    <NA>    <NA>    <NA>    <NA>    <NA>   
##  9 P. mirabilis  "kidne… <NA>    <NA>    <NA>    0.09    <NA>    <NA>    <NA>   
## 10 CoNS          "food … <NA>    <NA>    x       <NA>    <NA>    x       <NA>   
## 11 C. difficile  "sever… <NA>    <NA>    <NA>    <NA>    <NA>    <NA>    <NA>   
## 12 P. aeruginosa "lung,… yes     <NA>    <NA>    0.15    <NA>    <NA>    <NA>   
## 13 S. pneumoniae "pneum… <NA>    <NA>    0.08    <NA>    <NA>    <NA>    0.41   
## 14 E. coli       "food … yes     <NA>    <NA>    0.09    <NA>    <NA>    <NA>   
## 15 S. aureus     "boils… <NA>    <NA>    <NA>    <NA>    <NA>    <NA>    <NA>   
## 16 <NA>           <NA>   <NA>    <NA>    <NA>    <NA>    <NA>    <NA>    <NA>   
## 17 gram-negativ… "stron… <NA>    <NA>    <NA>    <NA>    <NA>    <NA>    <NA>   
## 18 <NA>           <NA>   <NA>    <NA>    <NA>    <NA>    <NA>    <NA>    <NA>   
## 19 <NA>           <NA>   <NA>    <NA>    <NA>    <NA>    <NA>    <NA>    <NA>   
## 20 <NA>           <NA>   Date i… <NA>    1942.0  <NA>    1944.0  1949.0  <NA>   
## # … with 40 more variables: Macrolides...10 <chr>, Other...11 <chr>,
## #   Glycopeptides <chr>, Tetracyclines <chr>, Aminoglycosides...14 <chr>,
## #   Penicillins...15 <chr>, `Penicillins_(Aminopenicillins)...16` <chr>,
## #   Penicillins...17 <chr>, Nitroimidazoles <chr>,
## #   `Penicillins_(Aminopenicillins)...19` <chr>, Sulfonamides <chr>,
## #   `Cephalosporins_(First_generation)P` <chr>,
## #   `Cephalosporins_(First_generation)` <chr>, Aminoglycosides...23 <chr>, …
## # ℹ Use `colnames()` to see all variable names
# Load data (assuming it's saved in a file called "data.csv")
df <- read.csv("../data/cleaned_antibiotic_data.csv", stringsAsFactors = FALSE, header = TRUE)

# Handle missing values:
# Replace "x" with NA and convert to numeric
df[df == "x"] <- NA
df[4:ncol(df)] <- lapply(df[4:ncol(df)], as.numeric)

# Handle columns:
# The first three columns seem to be about the bacterium name, its common diseases, and its gram-negative status. 
# For better clarity, we will rename them.
colnames(df)[1:3] <- c("BacteriumName", "Causes", "GramNegative")

# Removing rows that are not relevant to our analysis:
# Rows that contain only NAs or meta-information are removed.
df <- df %>% filter(!is.na(BacteriumName))

# As a suggestion, you might want to separate the antibiotics based on their family/group. 
# However, this would require domain knowledge about which antibiotic belongs to which group.

# You can save the cleaned data to a new CSV file if desired.
write.csv(df, "../data/cleaned_data.csv", row.names = FALSE)

# The data is now cleaned and saved as "cleaned_data.csv".
df
##                BacteriumName
## 1  Adding up drug resistance
## 2             Bacterium name
## 3                A. baumanii
## 4              K. pneumoniae
## 5                 E. faecium
## 6             N. gonorrhoeae
## 7                   Shigella
## 8            M. tuberculosis
## 9               P. mirabilis
## 10                      CoNS
## 11              C. difficile
## 12             P. aeruginosa
## 13             S. pneumoniae
## 14                   E. coli
## 15                 S. aureus
## 16    gram-negative bacteria
##                                                                             Causes
## 1  data are % of bacteria that are resistant, US\nx = resistance, but unquantified
## 2                                                                           Causes
## 3                                            "Iraqibacter" - pneumonia, meningitis
## 4                                        pneumonia, bronchitis, urinary infections
## 5                                                               urinary infections
## 6                                                                       gonorrhoea
## 7                                                                         dysentry
## 8                                                                     tuberculosis
## 9                                                           kidney stones, proteus
## 10                                                                  food poisoning
## 11                                                       severe diarrhoea, colitis
## 12                                   lung, urinary, skin, wound & blood infections
## 13                                   pneumonia, meningitis & many other infections
## 14                                                                  food poisoning
## 15                                                boils, sinusitis, food poisoning
## 16                                                 strong membrane, more resistant
##       GramNegative Penicillins...4 Penicillins...5 Aminoglycosides...6
## 1  Individual drug              NA              NA                  NA
## 2   Gram negative?              NA              NA                  NA
## 3              yes              NA              NA                0.46
## 4              yes              NA              NA                0.08
## 5             <NA>              NA              NA                  NA
## 6              yes             0.3              NA                  NA
## 7              yes              NA              NA                  NA
## 8             <NA>              NA              NA                  NA
## 9             <NA>              NA              NA                0.09
## 10            <NA>              NA              NA                  NA
## 11            <NA>              NA              NA                  NA
## 12             yes              NA              NA                0.15
## 13            <NA>              NA            0.08                  NA
## 14             yes              NA              NA                0.09
## 15            <NA>              NA              NA                  NA
## 16            <NA>              NA              NA                  NA
##    Aminoglycosides...7 Other...8 Macrolides...9 Macrolides...10 Other...11
## 1                   NA        NA             NA              NA         NA
## 2                   NA        NA             NA              NA         NA
## 3                   NA        NA             NA              NA         NA
## 4                   NA        NA             NA              NA         NA
## 5                   NA        NA             NA              NA         NA
## 6                   NA        NA             NA              NA         NA
## 7                 0.56      0.14             NA              NA         NA
## 8                   NA        NA             NA              NA       0.09
## 9                   NA        NA             NA              NA         NA
## 10                  NA        NA             NA              NA         NA
## 11                  NA        NA             NA              NA         NA
## 12                  NA        NA             NA              NA         NA
## 13                  NA        NA           0.41              NA         NA
## 14                  NA        NA             NA              NA         NA
## 15                  NA        NA             NA              NA         NA
## 16                  NA        NA             NA              NA         NA
##    Glycopeptides Tetracyclines Aminoglycosides...14 Penicillins...15
## 1             NA            NA                   NA               NA
## 2             NA            NA                   NA               NA
## 3             NA            NA                   NA               NA
## 4             NA            NA                   NA               NA
## 5           0.75            NA                   NA               NA
## 6             NA            NA                   NA               NA
## 7             NA          0.45                0.009               NA
## 8             NA            NA                   NA               NA
## 9             NA            NA                   NA               NA
## 10          0.00          0.16                   NA             0.63
## 11          0.11          0.03                   NA               NA
## 12            NA            NA                   NA               NA
## 13            NA            NA                   NA               NA
## 14            NA            NA                   NA               NA
## 15            NA            NA                   NA               NA
## 16            NA            NA                   NA               NA
##    Penicillins_.Aminopenicillins....16 Penicillins...17 Nitroimidazoles
## 1                                   NA               NA              NA
## 2                                   NA               NA              NA
## 3                                   NA               NA              NA
## 4                                   NA               NA              NA
## 5                                   NA               NA              NA
## 6                                   NA               NA              NA
## 7                                   NA               NA              NA
## 8                                   NA               NA              NA
## 9                                 0.22               NA              NA
## 10                                  NA               NA              NA
## 11                                  NA               NA               0
## 12                                  NA               NA              NA
## 13                                  NA               NA              NA
## 14                                0.45               NA              NA
## 15                                  NA             0.51              NA
## 16                                  NA               NA              NA
##    Penicillins_.Aminopenicillins....19 Sulfonamides
## 1                                   NA           NA
## 2                                   NA           NA
## 3                                   NA           NA
## 4                                   NA           NA
## 5                                   NA           NA
## 6                                   NA           NA
## 7                                 0.78         0.47
## 8                                   NA           NA
## 9                                   NA           NA
## 10                                  NA           NA
## 11                                  NA           NA
## 12                                  NA           NA
## 13                                  NA           NA
## 14                                  NA           NA
## 15                                  NA           NA
## 16                                  NA           NA
##    Cephalosporins_.First_generation.P Cephalosporins_.First_generation.
## 1                                  NA                                NA
## 2                                  NA                                NA
## 3                                  NA                                NA
## 4                                  NA                                NA
## 5                                  NA                                NA
## 6                                  NA                                NA
## 7                                  NA                              0.06
## 8                                  NA                                NA
## 9                                  NA                                NA
## 10                                 NA                                NA
## 11                                 NA                                NA
## 12                                 NA                                NA
## 13                                 NA                                NA
## 14                                 NA                                NA
## 15                                 NA                                NA
## 16                                 NA                                NA
##    Aminoglycosides...23 Fluoroquinolones Fluroquinolones...25 Rifamycin
## 1                    NA               NA                   NA        NA
## 2                    NA               NA                   NA        NA
## 3                    NA             0.58                   NA     0.000
## 4                    NA             0.11                   NA        NA
## 5                 0.190               NA                   NA        NA
## 6                    NA               NA                   NA        NA
## 7                 0.002             0.02                 0.01        NA
## 8                    NA               NA                   NA        NA
## 9                    NA             0.28                   NA        NA
## 10                   NA             0.50                   NA        NA
## 11                   NA               NA                   NA     0.100
## 12                   NA             0.27                   NA        NA
## 13                   NA               NA                   NA        NA
## 14                   NA             0.33                   NA        NA
## 15                   NA               NA                   NA     0.008
## 16                   NA               NA                   NA        NA
##    Lincosamides Sulfonamides_._other. Aminoglycosides...29 Penicillins...30
## 1            NA                    NA                   NA               NA
## 2            NA                    NA                   NA               NA
## 3            NA                    NA                0e+00               NA
## 4            NA                  0.15                   NA               NA
## 5            NA                    NA                   NA               NA
## 6            NA                    NA                   NA               NA
## 7            NA                  0.46                6e-04             0.02
## 8            NA                    NA                   NA               NA
## 9            NA                  0.27                   NA               NA
## 10         0.33                  0.34                   NA               NA
## 11         0.28                    NA                   NA               NA
## 12           NA                    NA                   NA               NA
## 13           NA                    NA                   NA               NA
## 14           NA                  0.25                   NA               NA
## 15           NA                    NA                   NA               NA
## 16           NA                    NA                   NA               NA
##    Cephalosporins_.Third_generation....31
## 1                                      NA
## 2                                      NA
## 3                                      NA
## 4                                    0.23
## 5                                      NA
## 6                                      NA
## 7                                      NA
## 8                                      NA
## 9                                    0.02
## 10                                     NA
## 11                                     NA
## 12                                     NA
## 13                                     NA
## 14                                   0.15
## 15                                     NA
## 16                                     NA
##    Cephalosporins_.Third_generation....32
## 1                                      NA
## 2                                      NA
## 3                                      NA
## 4                                      NA
## 5                                      NA
## 6                                   0.004
## 7                                   0.000
## 8                                      NA
## 9                                      NA
## 10                                     NA
## 11                                     NA
## 12                                     NA
## 13                                     NA
## 14                                     NA
## 15                                     NA
## 16                                     NA
##    Cephalosporins_.Third_generation....33 Carbapenems...34 Carbapenems...35
## 1                                      NA               NA               NA
## 2                                      NA               NA               NA
## 3                                    0.52             0.41               NA
## 4                                      NA             0.11               NA
## 5                                      NA               NA               NA
## 6                                      NA               NA               NA
## 7                                      NA               NA               NA
## 8                                      NA               NA               NA
## 9                                      NA               NA               NA
## 10                                     NA               NA               NA
## 11                                     NA               NA               NA
## 12                                   0.10             0.14               NA
## 13                                     NA               NA               NA
## 14                                     NA               NA               NA
## 15                                     NA               NA               NA
## 16                                     NA               NA               NA
##    Penicillins...36 ...37 Fluroquinolones...38 Fluroquinolones...39
## 1                NA    NA                   NA                   NA
## 2                NA    NA                   NA                   NA
## 3              0.25    NA                   NA                   NA
## 4                NA    NA                   NA                   NA
## 5                NA    NA                   NA                   NA
## 6              0.13    NA               0.1400                   NA
## 7                NA 6e-04               0.0006                   NA
## 8                NA    NA                   NA                   NA
## 9                NA    NA                   NA                   NA
## 10               NA    NA                   NA                   NA
## 11               NA    NA                   NA                 0.39
## 12               NA    NA                   NA                   NA
## 13               NA    NA                   NA                   NA
## 14               NA    NA                   NA                   NA
## 15               NA    NA                   NA                   NA
## 16               NA    NA                   NA                   NA
##    Penicillins...40 ...41 Multi_drug Remarks Resistance_score ...45
## 1                NA    NA         NA      NA               NA    NA
## 2                NA    NA         NA      NA               NA    NA
## 3                NA    NA      0.510      NA                4    NA
## 4                NA    NA      0.060      NA                2    NA
## 5                NA    NA         NA      NA                1    NA
## 6                NA    NA      0.300      NA                3    NA
## 7                NA    NA      0.640      NA                4    NA
## 8                NA    NA      0.600      NA                3    NA
## 9                NA    NA      0.006      NA                2    NA
## 10               NA    NA      0.130      NA                3    NA
## 11               NA    NA         NA      NA                3    NA
## 12             0.12    NA      0.100      NA                2    NA
## 13               NA    NA      0.080      NA                1    NA
## 14               NA    NA      0.015      NA                2    NA
## 15               NA    NA         NA      NA                1    NA
## 16               NA    NA         NA      NA               NA    NA
##    N_antibiotics_or_classes Average_percent_resistance ...48 Sources
## 1                        NA                         NA    NA      NA
## 2                        NA                         NA    NA      NA
## 3                        18                  0.3171429    NA      NA
## 4                         5                  0.1360000    NA      NA
## 5                         2                  0.4700000    NA      NA
## 6                         6                  0.1435000    NA      NA
## 7                        16                  0.1864250    NA      NA
## 8                         7                  0.0900000    NA      NA
## 9                         5                  0.1760000    NA      NA
## 10                        9                  0.3266667    NA      NA
## 11                        7                  0.1516667    NA      NA
## 12                        5                  0.1560000    NA      NA
## 13                        2                  0.2450000    NA      NA
## 14                        5                  0.2540000    NA      NA
## 15                        1                  0.2590000    NA      NA
## 16                       NA                         NA    NA      NA

Reconstruction

The following plot fixes the main issues in the original.

# Data
antibiotic_resistance_df <- data.frame(
  Bacterium_name = c('A. baumanii', 'K. pneumoniae', 'E. faecium', 'N. gonorrhoeae', 'Shigella', 
                     'M. tuberculosis', 'P. mirabilis', 'CoNS', 'C. difficile', 
                     'P. aeruginosa', 'S. pneumoniae', 'E. coli', 'S. aureus'),
  
  Causes = c('pneumonia, meningitis', 'pneumonia, bronchitis, urinary infections', 'urinary infections',
             'gonorrhoea', 'dysentry', 'tuberculosis', 'kidney stones, proteus', 'food poisoning',
             'severe diarrhoea, colitis', 'lung, urinary, skin, wound & blood infections', 
             'pneumonia, meningitis & many other infections', 'food poisoning', 'boils, sinusitis, food poisoning'),
  
  Gram_negative = c('yes', 'yes', 'no', 'yes', 'yes', 'no', 'yes', 'no', 'no', 'yes', 'no', 'yes', 'no'),

  Penicillin = c(46, 8, NA, 30, NA, NA, 9, NA, NA, 15, 8, 9, NA),
  Streptomycin = c(NA, NA, 75, NA, 56, 9, NA, NA, NA, NA, NA, NA, NA),
  Chloramphenicol = c(NA, NA, NA, NA, 14, NA, NA, NA, 3, NA, NA, NA, NA),
  Erythromycin = c(58, 11, 19, NA, 45, NA, 22, 16, 11, 27, NA, 45, 51),
  Isoniazid = c(NA, NA, NA, NA, 0.9, NA, NA, NA, NA, NA, NA, NA, 0.8),
  Vancomycin = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA),
  Tetracycline = c(NA, NA, NA, NA, 78, NA, NA, NA, NA, NA, NA, NA, NA),
  Kanamycin = c(NA, NA, NA, NA, 47, NA, NA, NA, NA, NA, NA, NA, NA),
  Oxacillin = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA),
  Methicillin = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA),
  Metronidazole = c(NA, NA, NA, NA, NA, NA, NA, NA, 10, NA, NA, NA, NA),
  Ampicillin = c(NA, NA, NA, NA, NA, NA, NA, NA, 28, NA, NA, NA, NA),
  Sulfamethoxazole = c(NA, NA, NA, NA, 6, NA, NA, NA, NA, NA, NA, 15, NA),
  Cefalotin = c(NA, NA, NA, NA, 0.2, NA, 2, NA, NA, NA, NA, NA, NA),
  Gentamicin = c(NA, NA, NA, NA, 2, NA, 1, NA, NA, 10, NA, NA, NA),
  Nalidixic_acid = c(NA, NA, NA, NA, 1, NA, NA, NA, NA, 14, NA, NA, NA),
  Rifampicin = c(NA, NA, NA, NA, 46, NA, NA, NA, NA, NA, NA, NA, NA),
  Clindamycin = c(NA, NA, NA, NA, 0.06, NA, NA, NA, NA, NA, NA, NA, NA),
  Trimethoprim_sulfa = c(NA, NA, NA, NA, 2, NA, NA, NA, NA, NA, NA, NA, NA),
  Amikacin = c(NA, NA, NA, NA, 0, NA, NA, NA, NA, NA, NA, NA, NA),
  Amoxicillin_clavulanic_acid = c(NA, NA, NA, NA, 0.06, NA, NA, NA, NA, NA, NA, NA, NA),
  Ceftriaxone = c(NA, NA, NA, NA, 0.06, NA, NA, NA, NA, NA, NA, NA, NA),
  Ceftazidime = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA),
  Imipenem = c(52, NA, NA, NA, 64, 60, 0.6, 13, 39, 12, 8, 1.5, NA),
  Ceftiofur = c(41, NA, NA, NA, NA, NA, NA, NA, NA, 10, NA, NA, NA),
  Ciprofloxacin = c(25, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA),
  Moxifloxacin = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA),
  Piperacillin_tazobactam = c(51, 6, NA, 30, NA, NA, NA, NA, NA, 10, NA, NA, NA)
)

# Antibiotic Introduction Dates
antibiotic_intro_dates <- data.frame(
  Antibiotic = c('Penicillin', 'Streptomycin', 'Chloramphenicol', 'Erythromycin', 'Isoniazid', 
                 'Vancomycin', 'Tetracycline', 'Kanamycin', 'Oxacillin', 'Methicillin', 'Metronidazole', 
                 'Ampicillin', 'Sulfamethoxazole', 'Cefalotin', 'Gentamicin', 'Nalidixic_acid', 
                 'Rifampicin', 'Clindamycin', 'Trimethoprim_sulfa', 'Amikacin', 'Amoxicillin_clavulanic_acid', 
                 'Ceftriaxone', 'Ceftazidime', 'Imipenem', 'Ceftiofur', 'Ciprofloxacin', 'Moxifloxacin', 
                 'Piperacillin_tazobactam'),
  
  Date_introduced = c(1942, 1944, 1949, 1952, 1952, 1955, 1955, 1958, 1959, 1960, 1960, 1961, 1961, 1964, 
                      1964, 1967, 1967, 1968, 1968, 1976, 1981, 1982, 1983, 1985, 1987, 1987, 1987, 1989)
)

# View the dataframes
head(antibiotic_resistance_df)
##    Bacterium_name                                    Causes Gram_negative
## 1     A. baumanii                     pneumonia, meningitis           yes
## 2   K. pneumoniae pneumonia, bronchitis, urinary infections           yes
## 3      E. faecium                        urinary infections            no
## 4  N. gonorrhoeae                                gonorrhoea           yes
## 5        Shigella                                  dysentry           yes
## 6 M. tuberculosis                              tuberculosis            no
##   Penicillin Streptomycin Chloramphenicol Erythromycin Isoniazid Vancomycin
## 1         46           NA              NA           58        NA         NA
## 2          8           NA              NA           11        NA         NA
## 3         NA           75              NA           19        NA         NA
## 4         30           NA              NA           NA        NA         NA
## 5         NA           56              14           45       0.9         NA
## 6         NA            9              NA           NA        NA         NA
##   Tetracycline Kanamycin Oxacillin Methicillin Metronidazole Ampicillin
## 1           NA        NA        NA          NA            NA         NA
## 2           NA        NA        NA          NA            NA         NA
## 3           NA        NA        NA          NA            NA         NA
## 4           NA        NA        NA          NA            NA         NA
## 5           78        47        NA          NA            NA         NA
## 6           NA        NA        NA          NA            NA         NA
##   Sulfamethoxazole Cefalotin Gentamicin Nalidixic_acid Rifampicin Clindamycin
## 1               NA        NA         NA             NA         NA          NA
## 2               NA        NA         NA             NA         NA          NA
## 3               NA        NA         NA             NA         NA          NA
## 4               NA        NA         NA             NA         NA          NA
## 5                6       0.2          2              1         46        0.06
## 6               NA        NA         NA             NA         NA          NA
##   Trimethoprim_sulfa Amikacin Amoxicillin_clavulanic_acid Ceftriaxone
## 1                 NA       NA                          NA          NA
## 2                 NA       NA                          NA          NA
## 3                 NA       NA                          NA          NA
## 4                 NA       NA                          NA          NA
## 5                  2        0                        0.06        0.06
## 6                 NA       NA                          NA          NA
##   Ceftazidime Imipenem Ceftiofur Ciprofloxacin Moxifloxacin
## 1          NA       52        41            25           NA
## 2          NA       NA        NA            NA           NA
## 3          NA       NA        NA            NA           NA
## 4          NA       NA        NA            NA           NA
## 5          NA       64        NA            NA           NA
## 6          NA       60        NA            NA           NA
##   Piperacillin_tazobactam
## 1                      51
## 2                       6
## 3                      NA
## 4                      30
## 5                      NA
## 6                      NA
head(antibiotic_intro_dates)
##        Antibiotic Date_introduced
## 1      Penicillin            1942
## 2    Streptomycin            1944
## 3 Chloramphenicol            1949
## 4    Erythromycin            1952
## 5       Isoniazid            1952
## 6      Vancomycin            1955

This heatmap provides a quick visual representation of resistance percentages for various bacteria against different antibiotics. The darker the color, the higher the resistance. The antibiotics are also ordered based on their introduction dates, which can give an idea about the evolution of resistance over time.

library(ggplot2)
library(reshape2)
library(RColorBrewer)
library(grid)  # Ensure the grid package is loaded for grid.text

# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))

# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic), ]

# Create an ordered factor for the Antibiotic based on Date_introduced
antibiotic_intro_dates$Antibiotic <- factor(antibiotic_intro_dates$Antibiotic, 
                                           levels = antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)])

# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)

# Append introduction date to antibiotic name and remove underscores
melted_df$display_name <- paste(gsub("_", " ", melted_df$variable), "(", melted_df$Date_introduced, ")")

# Ensure that display_name is a factor and ordered based on variable
melted_df$display_name <- factor(melted_df$display_name, levels = unique(melted_df$display_name[order(melted_df$variable)]))

# Plotting the heatmap
p <- ggplot(melted_df, aes(x = display_name, y = Bacterium_name)) +
  geom_tile(aes(fill = value), color = "white", width = 0.7, height = 0.7) +  # Adjust width and height to space out the tiles
  scale_fill_gradient(low = "grey90", high = "red", name = "Resistance %") +
  labs(x = "Individual Antibiotics", y = "Bacterium") +
  theme(axis.text.x = element_text(angle = 90, hjust = 1, size = 8), 
        plot.margin = margin(10, 10, 80, 10),   # Adjust bottom margin to make space for both texts
        panel.grid.major = element_line(colour = "gray", size = 0.25),  # Make the grid lines less obvious
        plot.background = element_rect(fill = "white", color = NA),    # White background with no border
        panel.background = element_rect(fill = "white", color = NA)) +  # White background with no border
  scale_x_discrete(position = "top") +
  ggtitle("Resistance of Bacteria to Various Antibiotics")

# Display plot
print(p)

# Display the main source text below the plot
grid::grid.text("Sources: Centre for Disease Dynamics, World Health Organisation, CDC (US data)", x = 0.01, y = 0.02, just = c("left", "bottom"), gp = grid::gpar(col = "gray", fontsize = 10, fontface = "italic"))

# Display the additional information below the main source text
grid::grid.text("Original image: informationisbeautiful.net | Data collected by July 2014", x = 0.01, y = 0.01, just = c("left", "bottom"), gp = grid::gpar(col = "gray", fontsize = 10, fontface = "italic"))

library(ggplot2)
library(reshape2)
library(RColorBrewer)

# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))

# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic), ]

# Create an ordered factor for the Antibiotic based on Date_introduced
antibiotic_intro_dates$Antibiotic <- factor(antibiotic_intro_dates$Antibiotic, 
                                           levels = antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)])

# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)

# Append introduction date to antibiotic name and remove underscores
melted_df$display_name <- paste(gsub("_", " ", melted_df$variable), "(", melted_df$Date_introduced, ")")

# Ensure that display_name is a factor and ordered based on variable
melted_df$display_name <- factor(melted_df$display_name, levels = unique(melted_df$display_name[order(melted_df$variable)]))

# Plotting the heatmap
p <- ggplot(melted_df, aes(x = display_name, y = Bacterium_name)) +
  geom_tile(aes(fill = value), color = "white", width = 0.7, height = 0.7) +  # Adjust width and height to space out the tiles
  scale_fill_gradient(low = "grey90", high = "red", name = "Resistance %") +
  labs(x = "Individual Antibiotics", y = "Bacterium") +
  theme(axis.text.x = element_text(angle = 90, hjust = 1, size = 8), 
        plot.margin = margin(10, 10, 60, 10),   # Adjust bottom margin to make space for source text
        panel.grid.major = element_line(colour = "gray", size = 0.25),  # Make the grid lines less obvious
        plot.background = element_rect(fill = "white", color = NA),    # White background with no border
        panel.background = element_rect(fill = "white", color = NA)) +  # White background with no border
  scale_x_discrete(position = "top") +
  ggtitle("Resistance of Bacteria to Various Antibiotics")

# Display plot
print(p)

# Display the source text below the plot
grid::grid.text("Sources: Centre for Disease Dynamics, World Health Organisation, CDC (US data)", x = 0.01, y = 0.01, just = c("left", "bottom"), gp = grid::gpar(col = "gray", fontsize = 10, fontface = "italic"))

library(ggplot2)
library(reshape2)
library(RColorBrewer)

# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))

# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic), ]

# Create an ordered factor for the Antibiotic based on Date_introduced
antibiotic_intro_dates$Antibiotic <- factor(antibiotic_intro_dates$Antibiotic, 
                                           levels = antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)])

# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)

# Append introduction date to antibiotic name and remove underscores
melted_df$display_name <- paste(gsub("_", " ", melted_df$variable), "(", melted_df$Date_introduced, ")")

# Ensure that display_name is a factor and ordered based on variable
melted_df$display_name <- factor(melted_df$display_name, levels = unique(melted_df$display_name[order(melted_df$variable)]))

# Plotting the heatmap
ggplot(melted_df, aes(x = display_name, y = Bacterium_name)) +
  geom_tile(aes(fill = value), color = "white", width = 0.9, height = 0.9) + # Increased spacing between tiles
  scale_fill_gradient(low = "grey90", high = "red", name = "Resistance %") +
  labs(x = "Antibiotics", y = "Bacterium") +
  theme(axis.text.x = element_text(angle = 90, hjust = 1, size = 8), 
        plot.margin = margin(10, 10, 40, 10), 
        panel.grid.major = element_line(color = "grey85")) + # Lightened grid lines
  scale_x_discrete(position = "top", expand = c(0.05, 0.05)) + # Added a bit of spacing around the x-axis
  ggtitle("Resistance of Bacteria to Various Antibiotics") +
  annotation_custom(
    ggplotGrob(
      ggplot() + 
        theme_void() +
        annotate("text", x = 0.5, y = 0.5, label = "Sources: Centre for Disease Dynamics, World Health Organisation, CDC (US data)", color = "gray", size = 5, fontface = "italic")
    ), 
    xmin = -Inf, xmax = -1, ymin = -Inf, ymax = -1.5
  ) 

library(ggplot2)
library(reshape2)
library(RColorBrewer)

# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))

# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic), ]

# Create an ordered factor for the Antibiotic based on Date_introduced
antibiotic_intro_dates$Antibiotic <- factor(antibiotic_intro_dates$Antibiotic, 
                                           levels = antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)])

# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)

# Append introduction date to antibiotic name and remove underscores
melted_df$display_name <- paste(gsub("_", " ", melted_df$variable), "(", melted_df$Date_introduced, ")")

# Ensure that display_name is a factor and ordered based on variable
melted_df$display_name <- factor(melted_df$display_name, levels = unique(melted_df$display_name[order(melted_df$variable)]))

# Plotting the heatmap
ggplot(melted_df, aes(x = display_name, y = Bacterium_name)) +
  geom_tile(aes(fill = value), color = "white", width = 0.7, height = 0.7) +  # Adjust width and height to space out the tiles
  scale_fill_gradient(low = "grey90", high = "red", name = "Resistance %") +
  labs(x = "Antibiotics", y = "Bacterium") +
  theme(axis.text.x = element_text(angle = 90, hjust = 1, size = 8), 
        plot.margin = margin(10, 10, 40, 10),
        panel.grid.major = element_line(colour = "gray", size = 0.25),  # Make the grid lines less obvious
        plot.background = element_rect(fill = "white", color = NA),    # White background with no border
        panel.background = element_rect(fill = "white", color = NA)) +  # White background with no border
  scale_x_discrete(position = "top") +
  ggtitle("Resistance of Bacteria to Various Antibiotics") +
  annotation_custom(
    grob = grid::textGrob(label = "Sources: Centre for Disease Dynamics, World Health Organisation, CDC (US data)", 
                          gp = grid::gpar(col = "gray", fontsize = 10, fontface = "italic")),
    xmin = -Inf, xmax = -Inf, ymin = -Inf, ymax = -Inf
  )

library(ggplot2)
library(reshape2)
library(RColorBrewer)

# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))

# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic), ]

# Create an ordered factor for the Antibiotic based on Date_introduced
antibiotic_intro_dates$Antibiotic <- factor(antibiotic_intro_dates$Antibiotic, 
                                           levels = antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)])

# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)

# Append introduction date to antibiotic name and remove underscores
melted_df$display_name <- paste(gsub("_", " ", melted_df$variable), "(", melted_df$Date_introduced, ")")

# Ensure that display_name is a factor and ordered based on variable
melted_df$display_name <- factor(melted_df$display_name, levels = unique(melted_df$display_name[order(melted_df$variable)]))

# Plotting the heatmap
ggplot(melted_df, aes(x = display_name, y = Bacterium_name)) +
  geom_tile(aes(fill = value), color = "white") +
  scale_fill_gradient(low = "grey90", high = "red", name = "Resistance %") +
  labs(x = "Antibiotics", y = "Bacterium") +
  theme(axis.text.x = element_text(angle = 90, hjust = 1, size = 8), 
        plot.margin = margin(10, 10, 40, 10)) + 
  scale_x_discrete(position = "top") +
  ggtitle("Resistance of Bacteria to Various Antibiotics") +
  annotate("text", x = Inf, y = Inf, label = "No major new antibiotics developed for 20 years",
           vjust = 2, hjust = 1.5, color = "black", size = 3, fontface = "italic") +
  annotate("text", x = 0, y = -1.5, label = "Sources: Centre for Disease Dynamics, World Health Organisation, CDC (US data)",
           vjust = 0, hjust = 0, color = "gray", size = 3, fontface = "italic")

library(ggplot2)
library(reshape2)
library(RColorBrewer)

# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))

# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic), ]

# Create an ordered factor for the Antibiotic based on Date_introduced
antibiotic_intro_dates$Antibiotic <- factor(antibiotic_intro_dates$Antibiotic, 
                                           levels = antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)])

# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)

# Remove underscores from antibiotic names
melted_df$variable <- gsub("_", " ", melted_df$variable)

# Append introduction date to antibiotic name
melted_df$variable_with_date <- paste(melted_df$variable, "(", melted_df$Date_introduced, ")")

# Ensure that variable_with_date is a factor
melted_df$variable_with_date <- as.factor(melted_df$variable_with_date)

# Plotting the heatmap
ggplot(melted_df, aes(x = variable_with_date, y = Bacterium_name)) +
  geom_tile(aes(fill = value), color = "white") +
  scale_fill_gradient(low = "grey90", high = "red", name = "Resistance %") +
  labs(x = "Antibiotics", y = "Bacterium") +
  theme(axis.text.x = element_text(angle = 90, hjust = 1, size = 8),
        plot.margin = margin(10, 10, 60, 10)) +
  scale_x_discrete(position = "top") +
  ggtitle("Resistance of Bacteria to Various Antibiotics") +
  annotate("text", x = Inf, y = Inf, label = "No major new antibiotics developed for 20 years",
           vjust = 2, hjust = 1.5, color = "black", size = 3, fontface = "italic") +
  annotate("text", x = 1, y = -2, label = "Sources: Centre for Disease Dynamics, World Health Organisation, CDC (US data)",
           vjust = 0, hjust = 0, color = "gray", size = 3, fontface = "italic")

library(ggplot2)
library(reshape2)
library(RColorBrewer)

# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))

# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic), ]

# Create an ordered factor for the Antibiotic based on Date_introduced
antibiotic_intro_dates$Antibiotic <- factor(antibiotic_intro_dates$Antibiotic, 
                                           levels = antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)])

# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)

# Append introduction date to antibiotic name and remove underscores
melted_df$variable <- paste(gsub("_", " ", melted_df$variable), "(", melted_df$Date_introduced, ")")

# Ensure that variable is a factor
melted_df$variable <- as.factor(melted_df$variable)

# Plotting the heatmap
ggplot(melted_df, aes(x = variable, y = Bacterium_name)) +
  geom_tile(aes(fill = value), color = "white") +
  scale_fill_gradient(low = "grey90", high = "red", name = "Resistance %") +
  labs(x = "Antibiotics", y = "Bacterium") +
  theme(axis.text.x = element_text(angle = 90, hjust = 1, size = 8), 
        plot.margin = margin(10, 10, 40, 10)) + 
  scale_x_discrete(position = "top") +
  ggtitle("Resistance of Bacteria to Various Antibiotics") +
  annotate("text", x = Inf, y = Inf, label = "No major new antibiotics developed for 20 years",
           vjust = 2, hjust = 1.5, color = "black", size = 3, fontface = "italic") +
  annotate("text", x = 0, y = -1, label = "Sources: Centre for Disease Dynamics, World Health Organisation, CDC (US data)",
           vjust = 0, hjust = 0, color = "gray", size = 3, fontface = "italic")

library(ggplot2)
library(reshape2)
library(RColorBrewer)

# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))

# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic), ]

# Create an ordered factor for the Antibiotic based on Date_introduced
antibiotic_intro_dates$Antibiotic <- factor(antibiotic_intro_dates$Antibiotic, 
                                           levels = antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)])

# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)

# Ensure that variable is a factor
melted_df$variable <- as.factor(melted_df$variable)

# Plotting the heatmap
ggplot(melted_df, aes(x = variable, y = Bacterium_name)) +
  geom_tile(aes(fill = value), color = "white") +
  scale_fill_gradient(low = "grey90", high = "red", name = "Resistance %") +
  labs(x = "Antibiotics", y = "Bacterium") +
  theme(axis.text.x = element_text(angle = 90, hjust = 1, size = 8), 
        plot.margin = margin(10, 10, 40, 10)) + 
  scale_x_discrete(position = "top") +
  ggtitle("Resistance of Bacteria to Various Antibiotics") +
  annotate("text", x = Inf, y = Inf, label = "No major new antibiotics developed for 20 years",
           vjust = 2, hjust = 1.5, color = "black", size = 3, fontface = "italic") +
  annotate("text", x = 0, y = -Inf, label = "Sources: Centre for Disease Dynamics, World Health Organisation, CDC (US data)",
           vjust = 0, hjust = 0, color = "gray", size = 3, fontface = "italic")

library(ggplot2)
library(reshape2)
library(RColorBrewer)

# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))

# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic), ]

# Create an ordered factor for the Antibiotic based on Date_introduced
ordered_antibiotics <- antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)]
melted_df$variable <- factor(melted_df$variable, levels = ordered_antibiotics)

# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)

# Append introduction date to antibiotic name
melted_df$variable_label <- paste(melted_df$variable, "(", melted_df$Date_introduced, ")")

# Plotting the heatmap
ggplot(melted_df, aes(x = variable_label, y = Bacterium_name)) +
  geom_tile(aes(fill = value), color = "white") +
  scale_fill_gradient(low = "grey90", high = "red", name = "Resistance %") +
  labs(x = "Antibiotics", y = "Bacterium") +
  theme(axis.text.x = element_text(angle = 90, hjust = 1, size = 8), 
        plot.margin = margin(10, 10, 40, 10)) + 
  scale_x_discrete(position = "top") +
  ggtitle("Resistance of Bacteria to Various Antibiotics") +
  annotate("text", x = -Inf, y = -Inf, hjust = 0, vjust = 0, label = "Sources: Centre for Disease Dynamics, World Health Organisation, CDC (US data)", 
           color = "gray", size = 3, fontface = "italic") +
  annotate("text", x = Inf, y = Inf, label = "No major new antibiotics developed for 20 years",
           vjust = 2, hjust = 1.5, color = "black", size = 3, fontface = "italic")

library(ggplot2)
library(reshape2)
library(RColorBrewer)

# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))

# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic), ]

# Create an ordered factor for the Antibiotic based on Date_introduced
antibiotic_intro_dates$Antibiotic <- factor(antibiotic_intro_dates$Antibiotic, 
                                           levels = antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)])

# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)

# Append introduction date to antibiotic name
melted_df$variable <- paste(melted_df$variable, "(", melted_df$Date_introduced, ")")

# Ensure that variable is a factor
melted_df$variable <- as.factor(melted_df$variable)

# Plotting the heatmap
ggplot(melted_df, aes(x = variable, y = Bacterium_name)) +
  geom_tile(aes(fill = value), color = "white") +
  scale_fill_gradient(low = "grey90", high = "red", name = "Resistance %") +
  labs(x = "Antibiotics", y = "Bacterium") +
  theme(axis.text.x = element_text(angle = 90, hjust = 1, size = 8), 
        plot.margin = margin(10, 10, 40, 10)) + 
  scale_x_discrete(position = "top") +
  ggtitle("Resistance of Bacteria to Various Antibiotics") +
  annotate("text", x = Inf, y = Inf, label = "No major new antibiotics developed for 20 years",
           vjust = 2, hjust = 1.5, color = "black", size = 3, fontface = "italic")

library(ggplot2)
library(reshape2)
library(RColorBrewer)

# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))

# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic), ]

# Create an ordered factor for the Antibiotic based on Date_introduced
antibiotic_intro_dates$Antibiotic <- factor(antibiotic_intro_dates$Antibiotic, 
                                           levels = antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)])

# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)

# Append introduction date to antibiotic name
melted_df$variable <- paste(melted_df$variable, "(", melted_df$Date_introduced, ")")

# Ensure that variable is a factor
melted_df$variable <- as.factor(melted_df$variable)

# Plotting the heatmap
ggplot(melted_df, aes(x = variable, y = Bacterium_name)) +
  geom_tile(aes(fill = value), color = "white") +
  scale_fill_gradient(low = "grey90", high = "red", name = "Resistance %") +
  labs(x = "Antibiotics", y = "Bacterium") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
  scale_x_discrete(position = "top") +
  ggtitle("Resistance of Bacteria to Various Antibiotics") +
  annotate("text", x = Inf, y = Inf, label = "No major new antibiotics developed for 20 years",
           vjust = 2, hjust = 1.5, color = "black", size = 3, fontface = "italic")

library(ggplot2)
library(reshape2)
library(RColorBrewer)

# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))

# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic), ]

# Create an ordered factor for the Antibiotic based on Date_introduced
antibiotic_intro_dates$Antibiotic <- factor(antibiotic_intro_dates$Antibiotic, 
                                           levels = antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)])

# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)

# Order antibiotics by introduction date for plotting
melted_df$variable <- factor(melted_df$variable, levels = levels(antibiotic_intro_dates$Antibiotic))

# Ensure that variable is a factor
melted_df$variable <- as.factor(melted_df$variable)

# Convert Date_introduced to character if it isn't
melted_df$Date_introduced <- as.character(melted_df$Date_introduced)

# Create a label that combines the antibiotic name and its introduction date
melted_df$label <- paste0(melted_df$variable, "\n(", melted_df$Date_introduced, ")")

# Plotting the heatmap
ggplot(melted_df, aes(x = variable, y = Bacterium_name)) +
  geom_tile(aes(fill = value), color = "white") +
  scale_fill_gradient(low = brewer.pal(9, "Spectral")[1], 
                      high = brewer.pal(9, "Spectral")[9], name = "Resistance %") +
  labs(x = "Antibiotics", y = "Bacterium") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1, size = 8)) + 
  scale_x_discrete(labels = melted_df$label, position = "top") +
  ggtitle("Resistance of Bacteria to Various Antibiotics") +
  annotate("text", x = Inf, y = Inf, label = "No major new antibiotics developed for 20 years", 
           vjust = 2, hjust = 1.5, color = "black", size = 3, fontface = "italic")

library(ggplot2)
library(reshape2)
library(RColorBrewer)

# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))

# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic), ]

# Create an ordered factor for the Antibiotic based on Date_introduced
antibiotic_intro_dates$Antibiotic <- factor(antibiotic_intro_dates$Antibiotic, 
                                           levels = antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)])

# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)

# Order antibiotics by introduction date for plotting
melted_df$variable <- factor(melted_df$variable, levels = levels(antibiotic_intro_dates$Antibiotic))

# Ensure that variable is a factor
melted_df$variable <- as.factor(melted_df$variable)

# Convert Date_introduced to character if it isn't
melted_df$Date_introduced <- as.character(melted_df$Date_introduced)

# Plotting the heatmap
ggplot(melted_df, aes(x = variable, y = Bacterium_name)) +
  geom_tile(aes(fill = value), color = "white") +
  geom_text(aes(label = Date_introduced), vjust = 1.5, color = "black", size = 2.5) +
  scale_fill_gradient(low = brewer.pal(9, "Spectral")[1], 
                      high = brewer.pal(9, "Spectral")[9], name = "Resistance %") +
  labs(x = "Antibiotics", y = "Bacterium") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) + 
  scale_x_discrete(position = "top") +
  ggtitle("Resistance of Bacteria to Various Antibiotics") +
  annotate("text", x = Inf, y = Inf, label = "No major new antibiotics developed for 20 years", 
           vjust = 2, hjust = 1.5, color = "black", size = 3, fontface = "italic")

library(ggplot2)
library(reshape2)
library(RColorBrewer) # To use color palettes

# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))

# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic), ]

# Create an ordered factor for the Antibiotic based on Date_introduced
antibiotic_intro_dates$Antibiotic <- factor(antibiotic_intro_dates$Antibiotic, 
                                           levels = antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)])

# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)

# Order antibiotics by introduction date for plotting
melted_df$variable <- factor(melted_df$variable, levels = levels(antibiotic_intro_dates$Antibiotic))

# Create new labels for the x-axis that combine the antibiotic name with its introduction date
melted_df$label <- paste(melted_df$variable, melted_df$Date_introduced, sep = "\n")

# Plotting the heatmap
ggplot(melted_df, aes(x = label, y = Bacterium_name)) +
  geom_tile(aes(fill = value), color = "white") +
  scale_fill_distiller(palette = "RdYlBu", direction = 1, name = "Resistance %") + # Use a color-blind friendly palette
  labs(x = "Antibiotics\n(Date Introduced)", y = "Bacterium") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) + 
  scale_x_discrete(position = "top") +
  ggtitle("Resistance of Bacteria to Various Antibiotics")

library(ggplot2)
library(reshape2)

# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))

# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic")

# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic), ]

# Create an ordered factor for the Antibiotic based on Date_introduced
antibiotic_intro_dates$Antibiotic <- factor(antibiotic_intro_dates$Antibiotic, 
                                           levels = antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)])

# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)

# Order antibiotics by introduction date for plotting
melted_df$variable <- factor(melted_df$variable, levels = levels(antibiotic_intro_dates$Antibiotic))

# Continue with the rest of the plotting code

# Plotting the heatmap
ggplot(melted_df, aes(x = variable, y = Bacterium_name)) +
  geom_tile(aes(fill = value), color = "white") +
  scale_fill_gradient(low = "white", high = "red", name = "Resistance %") +
  labs(x = "Antibiotics", y = "Bacterium") +
  theme(axis.text.x = element_text(angle = 45, hjust = 1)) + 
  scale_x_discrete(position = "top") +
  ggtitle("Resistance of Bacteria to Various Antibiotics")

# Data
antibiotic_resistance_df <- data.frame(
  Bacterium_name = c('A. baumanii', 'K. pneumoniae', 'E. faecium', 'N. gonorrhoeae', 'Shigella', 
                     'M. tuberculosis', 'P. mirabilis', 'CoNS', 'C. difficile', 
                     'P. aeruginosa', 'S. pneumoniae', 'E. coli', 'S. aureus'),
  Causes = c('pneumonia, meningitis', 'pneumonia, bronchitis', 'urinary infections', 
             'gonorrhoea', 'dysentry', 'tuberculosis', 'kidney stones, proteus', 'food poisoning',
             'severe diarrhoea, colitis', 'lung, urinary, skin, wound & blood infections', 
             'pneumonia, meningitis & many other infections', 'food poisoning', 'boils, sinusitis, food poisoning'),
  Gram_negative = c('yes', 'yes', 'no', 'yes', 'yes', 'no', 'yes', 'no', 'no', 'yes', 'no', 'yes', 'no'),
  Penicillin = c(46, 8, NA, 30, NA, NA, 9, NA, NA, 15, 8, 9, NA),
  Streptomycin = c(NA, NA, NA, NA, 56, NA, NA, NA, NA, NA, NA, NA, NA),
  Erythromycin = c(58, 11, 19, NA, NA, 9, NA, 16, 11, 27, 41, NA, 51)
  # Add other antibiotics columns as needed
)

# View the dataframe
head(antibiotic_resistance_df)
##    Bacterium_name                Causes Gram_negative Penicillin Streptomycin
## 1     A. baumanii pneumonia, meningitis           yes         46           NA
## 2   K. pneumoniae pneumonia, bronchitis           yes          8           NA
## 3      E. faecium    urinary infections            no         NA           NA
## 4  N. gonorrhoeae            gonorrhoea           yes         30           NA
## 5        Shigella              dysentry           yes         NA           56
## 6 M. tuberculosis          tuberculosis            no         NA           NA
##   Erythromycin
## 1           58
## 2           11
## 3           19
## 4           NA
## 5           NA
## 6            9
library(ggplot2)
library(tidyr)
library(RColorBrewer)

# Data
antibiotic_resistance_df <- data.frame(
  Bacterium_name = c('A. baumanii', 'K. pneumoniae', 'E. faecium'),
  Causes = c('pneumonia, meningitis', 'pneumonia, bronchitis', 'urinary infections'),
  Gram_negative = c('yes', 'yes', 'no'),
  Penicillin = c(46, 8, NA),
  Streptomycin = c(NA, NA, 75),
  Erythromycin = c(58, 11, 19)
)

# Reshape data for plotting
df_long <- antibiotic_resistance_df %>% 
  gather(key = 'Antibiotic', value = 'Resistance', Penicillin, Streptomycin, Erythromycin)

# Colorblind-friendly palette
cb_palette <- brewer.pal(n = 3, name = "Set2")

plot <- ggplot(df_long, aes(x = Bacterium_name, y = Resistance, fill = Antibiotic)) +
  geom_bar(stat = "identity", position = "dodge") +
  facet_wrap(~Gram_negative, scales = "free", ncol = 2) +
  labs(
    title = "Antibiotic Resistance Across Different Bacteria",
    subtitle = "Faceted by Gram-negative Status",
    x = "Bacterium",
    y = "Resistance (%)",
    caption = "Sources: Centre for Disease Dynamics, World Health Organisation, CDC (US data)"
  ) +
  scale_fill_manual(values = cb_palette) +
  theme_minimal() +
  theme(legend.position = "top", plot.caption = element_text(hjust = 1, color = "gray"))

print(plot)

library(ggplot2)
library(tidyr)

# Updated data
antibiotic_resistance_df <- data.frame(
  Bacterium_name = c('A. baumanii', 'K. pneumoniae', 'E. coli', 'E. faecium', 'S. aureus', 'P. aeruginosa', 'Enterococcus'),
  Causes = c('pneumonia, meningitis', 'pneumonia, bronchitis', 'gastrointestinal infections', 'urinary infections', 'skin infections', 'sepsis, skin infections', 'urinary tract, bloodstream infections'),
  Gram_negative = c('yes', 'yes', 'yes', 'no', 'no', 'yes', 'no'),
  Penicillin = c(46, 8, 12, NA, 90, 23, NA),
  Streptomycin = c(NA, NA, 75, 85, 15, 26, 50),
  Erythromycin = c(58, 11, 19, 30, 45, 40, 38)
)

# Reshape data for plotting
df_long <- antibiotic_resistance_df %>% 
  gather(key = 'Antibiotic', value = 'Resistance', Penicillin, Streptomycin, Erythromycin)

# Comprehensive Visualization
plot <- ggplot(df_long, aes(x = Bacterium_name, y = Resistance, fill = Antibiotic)) +
  geom_bar(stat = "identity", position = "dodge") +
  facet_wrap(~Gram_negative, scales = "free", ncol = 2) +
  labs(
    title = "Antibiotic Resistance Across Different Bacteria",
    subtitle = "Faceted by Gram-negative Status",
    x = "Bacterium",
    y = "Resistance (%)",
    caption = "Sources: Centre for Disease Dynamics, World Health Organisation, CDC (US data)\nInspiration from: https://informationisbeautiful.net/visualizations/antibiotic-resistance/"
  ) +
  theme_minimal() +
  theme(legend.position = "top", plot.caption = element_text(hjust = 1, color = "gray"))

# Display the plot
print(plot)

# Save the plot to the ../images directory
ggsave(filename = "../images/antibiotic_resistance_plot.png", plot = plot, width = 20, height = 15)
library(RColorBrewer)

# Colorblind-friendly palette for 3 groups
cb_palette <- brewer.pal(n = 3, name = "Set2")

plot <- ggplot(df_long, aes(x = Bacterium_name, y = Resistance, fill = Antibiotic)) +
  geom_bar(stat = "identity", position = "dodge") +
  facet_wrap(~Gram_negative, scales = "free", ncol = 2) +
  labs(
    title = "Antibiotic Resistance Across Different Bacteria",
    subtitle = "Faceted by Gram-negative Status",
    x = "Bacterium",
    y = "Resistance (%)",
    caption = "Sources: Centre for Disease Dynamics, World Health Organisation, CDC (US data)\nInspiration from: https://informationisbeautiful.net/visualizations/antibiotic-resistance/"
  ) +
  scale_fill_manual(values = cb_palette) +
  theme_minimal() +
  theme(legend.position = "top", plot.caption = element_text(hjust = 1, color = "gray"))

print(plot)

Reconstructed plot.

Reconstructed plot.

library(ggplot2)
library(tidyr)

# Updated data
antibiotic_resistance_df <- data.frame(
  Bacterium_name = c('A. baumanii', 'K. pneumoniae', 'E. coli', 'E. faecium', 'S. aureus', 'P. aeruginosa', 'Enterococcus'),
  Causes = c('pneumonia, meningitis', 'pneumonia, bronchitis', 'gastrointestinal infections', 'urinary infections', 'skin infections', 'sepsis, skin infections', 'urinary tract, bloodstream infections'),
  Gram_negative = c('yes', 'yes', 'yes', 'no', 'no', 'yes', 'no'),
  Penicillin = c(46, 8, 12, NA, 90, 23, NA),
  Streptomycin = c(NA, NA, 75, 85, 15, 26, 50),
  Erythromycin = c(58, 11, 19, 30, 45, 40, 38)
)

# Reshape data for plotting
df_long <- antibiotic_resistance_df %>% 
  gather(key = 'Antibiotic', value = 'Resistance', Penicillin, Streptomycin, Erythromycin)

# Comprehensive Visualization
ggplot(df_long, aes(x = Bacterium_name, y = Resistance, fill = Antibiotic)) +
  geom_bar(stat = "identity", position = "dodge") +
  facet_wrap(~Gram_negative, scales = "free", ncol = 2) +
  labs(
    title = "Antibiotic Resistance Across Different Bacteria",
    subtitle = "Faceted by Gram-negative Status",
    x = "Bacterium",
    y = "Resistance (%)",
    caption = "Sources: Centre for Disease Dynamics, World Health Organisation, CDC (US data)\nInspiration from: https://informationisbeautiful.net/visualizations/antibiotic-resistance/"
  ) +
  theme_minimal() +
  theme(legend.position = "top", plot.caption = element_text(hjust = 1))

library(ggplot2)
library(tidyr)
library(grid)

# Updated data
antibiotic_resistance_df <- data.frame(
  Bacterium_name = c('A. baumanii', 'K. pneumoniae', 'E. coli', 'E. faecium', 'S. aureus', 'P. aeruginosa', 'Enterococcus'),
  Causes = c('pneumonia, meningitis', 'pneumonia, bronchitis', 'gastrointestinal infections', 'urinary infections', 'skin infections', 'sepsis, skin infections', 'urinary tract, bloodstream infections'),
  Gram_negative = c('yes', 'yes', 'yes', 'no', 'no', 'yes', 'no'),
  Penicillin = c(46, 8, 12, NA, 90, 23, NA),
  Streptomycin = c(NA, NA, 75, 85, 15, 26, 50),
  Erythromycin = c(58, 11, 19, 30, 45, 40, 38)
)

# Reshape data for plotting
df_long <- antibiotic_resistance_df %>% 
  gather(key = 'Antibiotic', value = 'Resistance', Penicillin, Streptomycin, Erythromycin)

# Create the plot and save it to an object
p <- ggplot(df_long, aes(x = Bacterium_name, y = Resistance, fill = Antibiotic)) +
  geom_bar(stat = "identity", position = "dodge") +
  facet_wrap(~Gram_negative, scales = "free", ncol = 2) +
  labs(
    title = "Antibiotic Resistance Across Different Bacteria",
    subtitle = "Faceted by Gram-negative Status",
    x = "Bacterium",
    y = "Resistance (%)"
  ) +
  theme_minimal() +
  theme(legend.position = c(1, 1), legend.justification = c(1, 1))

# Print the plot
print(p)

# Add the source text using grid package
grid.text("Sources: Centre for Disease Dynamics, World Health Organisation, CDC (US data)\nInspiration from: https://informationisbeautiful.net/visualizations/antibiotic-resistance/",
          x = 1, y = 1.03, hjust = 1, gp = gpar(col = "darkgray", fontsize = 8))

References

The reference to the original data visualisation choose, the data source(s) used for the reconstruction and any other sources used for this assignment are as follows:

Acknowledgments

Baglin, J. (2023). Data Visualisation: From Theory to Practice. In Data Visualisation and Communication (2350) [Online Textbook]. RMIT University. Retrieved from https://dark-star161610.appspot.com/secured/_book/index.html